﻿using System;
using ExFlash.Records;

namespace ExFlash.Tags
{
    public class DefineSceneAndFrameLabelDataTag : Tag
    {
        private readonly int _swfVersion;

        public EncodedU32 SceneCount
        {
            get;
            private set;
        }

        public EncodedData[] Scenes
        {
            get;
            private set;
        }

        public EncodedU32 FrameLabelCount
        {
            get;
            private set;
        }

        public EncodedData[] Frames
        {
            get;
            private set;
        }

        public DefineSceneAndFrameLabelDataTag(int len, int version, Int32 offset)
            : base(TagCodes.DefineSceneAndFrameLabelData, len, offset)
        {
            _swfVersion = version;
        }
        
        public override void SwfDeserialize(BinaryBitReader reader)
        {
            SceneCount = new EncodedU32();
            SceneCount.SwfDeserialize(reader);

            Scenes = new EncodedData[SceneCount];

            for (int i = 0; i < SceneCount; i++ )
            {
                Scenes[i] = new EncodedData(_swfVersion);
                Scenes[i].SwfDeserialize(reader);
            }

            FrameLabelCount = new EncodedU32();
            FrameLabelCount.SwfDeserialize(reader);

            Frames = new EncodedData[FrameLabelCount];

            for (int i = 0; i < FrameLabelCount; i++)
            {
                Frames[i] = new EncodedData(_swfVersion);
                Frames[i].SwfDeserialize(reader);
            }
        }

        public override void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }
    }
}
